#
# AS - C++ Application server
#
PROJECT(cas)

CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0 FATAL_ERROR)

# ################################################################################
# Defaults
#
OPTION(DEBUG_MODE          "Enable debug output [default: OFF]" OFF)
OPTION(ENABLE_OPTIMIZATION "Enable optimization [default: OFF]" ON)

# ################################################################################
# Macroses
#

# Standard CMake macroses
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckCXXSourceCompiles)
INCLUDE(CheckSymbolExists)
INCLUDE(CheckLibraryExists)

# User-defined macroses
INCLUDE(cmake/ConfigureLibrary.cmake)
INCLUDE(cmake/ConfigurePackage.cmake)
INCLUDE(cmake/RenameModule.cmake)

# ################################################################################
# Set system-specific data
#
MESSAGE(STATUS "#### System name is: ${CMAKE_SYSTEM_NAME}")

#
# Configure CTPP2 package
#
CONFIGURE_PACKAGE(ctpp2-config ctpp2 CTPP2)

#
# Configure CAS package
#
CONFIGURE_PACKAGE(cas-config cas CAS)

# CAS memcached connector
CONFIGURE_LIBRARY(ASMemcached.hpp "/usr/include/cas/modules /usr/local/include/cas/modules /opt/include/cas/modules"
                  casmemcached    "/lib /usr/lib /usr/local/lib /opt/lib")

# ################################################################################
# Setup libraries & headers
#

INCLUDE_DIRECTORIES(include)

# ################################################################################
# Platform-specific options
#

IF("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD")
	MESSAGE(STATUS "Building for FreeBSD...")
ENDIF("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD")

IF("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
	MESSAGE(STATUS "Building for Linux...")
ENDIF("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")

IF("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS")
	MESSAGE(STATUS "Building for SunOS...")
ENDIF("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS")

IF("${CMAKE_COMPILER_IS_GNUCXX}" MATCHES "1")

	SET(CMAKE_CXX_PARAMS " --param large-function-growth=6000 --param large-function-growth=5000 --param inline-unit-growth=200 --param max-inline-insns-single=1000 ")
	SET(CMAKE_CXX_WARN_FLAGS " -Wall -pedantic -Wno-long-long -Winline -finline-functions ")

	IF(ENABLE_OPTIMIZATION MATCHES "ON")
		SET(CMAKE_CXX_FLAGS "${CXX_FLAGS} ${CMAKE_CXX_WARN_FLAGS} ${CMAKE_CXX_PARAMS} -O3 -fomit-frame-pointer -funroll-loops ")
	ELSE(ENABLE_OPTIMIZATION MATCHES "OFF")
		SET(CMAKE_CXX_FLAGS "${CXX_FLAGS} ${CMAKE_CXX_WARN_FLAGS} ${CMAKE_CXX_PARAMS} ")
	ENDIF(ENABLE_OPTIMIZATION MATCHES "ON")

	IF(DEBUG_MODE MATCHES "ON")
		SET(CMAKE_CXX_FLAGS "${CXX_FLAGS} ${CMAKE_CXX_WARN_FLAGS} ${CMAKE_CXX_PARAMS} -g -D_DEBUG ")
	ENDIF(DEBUG_MODE MATCHES "ON")

ENDIF("${CMAKE_COMPILER_IS_GNUCXX}" MATCHES "1")

# ################################################################################
# Lib binary
#

ADD_LIBRARY(mod_csrf_module MODULE src/ASCSRFModule.cpp)
TARGET_LINK_LIBRARIES(mod_csrf_module ${HAVE_ctpp2} ${HAVE_cas} ${HAVE_casmemcached})
RENAME_MODULE(mod_csrf_module mod_csrf_module)

# ################################################################################
# Install modules
#
INSTALL(FILES mod_csrf_module.so
        DESTINATION libexec/cas
        PERMISSIONS OWNER_READ OWNER_WRITE
                    GROUP_READ
                    WORLD_READ)

# End.
